package xyz.redtorch.client.service.impl;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.stereotype.Service;

import xyz.redtorch.client.service.ClientTradeCacheService;
import xyz.redtorch.pb.CoreField.AccountField;
import xyz.redtorch.pb.CoreField.ContractField;
import xyz.redtorch.pb.CoreField.OrderField;
import xyz.redtorch.pb.CoreField.PositionField;
import xyz.redtorch.pb.CoreField.TickField;
import xyz.redtorch.pb.CoreField.TradeField;

/**
 * @author Skywalker
 *
 */
@Service
public class ClientTradeCacheServiceImpl implements ClientTradeCacheService {

	private Map<String, OrderField> orderDict = new ConcurrentHashMap<>();
	private Map<String, TradeField> tradeDict = new ConcurrentHashMap<>();
	private Map<String, PositionField> positionDict = new ConcurrentHashMap<>();
	private Map<String, ContractField> mixContractDict = new ConcurrentHashMap<>();
	private Map<String, AccountField> accountDict = new ConcurrentHashMap<>();
	private Map<String, TickField> mixTickDict = new ConcurrentHashMap<>();

	@Override
	public Map<String, OrderField> getOrderDict() {
		return orderDict;
	}

	@Override
	public Map<String, TradeField> getTradeDict() {
		return tradeDict;
	}

	@Override
	public Map<String, PositionField> getPositionDict() {
		return positionDict;
	}

	@Override
	public Map<String, ContractField> getMixContractDict() {
		return mixContractDict;
	}

	@Override
	public Map<String, AccountField> getAccountDict() {
		return accountDict;
	}

	public Map<String, TickField> getMixTickDict() {
		return mixTickDict;
	}

	@Override
	public void storeOrder(OrderField order) {
		orderDict.put(order.getOrderId(), order);
	}

	@Override
	public void storeTrade(TradeField trade) {
		tradeDict.put(trade.getTradeId(), trade);
	}

	@Override
	public void storeContract(ContractField contract) {
		mixContractDict.put(contract.getUnifiedSymbol(), contract);
	}

	@Override
	public void storePosition(PositionField position) {
		positionDict.put(position.getPositionId(), position);
	}

	@Override
	public void storeAccount(AccountField account) {
		accountDict.put(account.getAccountId(), account);
	}

	@Override
	public void storeTick(TickField tick) {
		mixTickDict.put(tick.getUnifiedSymbol(), tick);
	}

}
